package com.yuexunit.operationman.nbsy.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.module.SurgicalReceipt.Bean.CompareBean;
import com.yuexunit.operationman.nbsy.util.ScreenUtil;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/10/29 0029.
 */

public class CompareDialog2 extends Dialog{

    @Bind(R.id.compare_name_tv_01)
    TextView compareNameTv01;
    @Bind(R.id.compare_name_tv_02)
    TextView compareNameTv02;
    @Bind(R.id.compare_type_01_01)
    TextView compareType0101;
    @Bind(R.id.compare_type_01_02)
    TextView compareType0102;
    @Bind(R.id.compare_type_ll_01)
    LinearLayout compareTypeLl01;
    @Bind(R.id.compare_type_02_01)
    TextView compareType0201;
    @Bind(R.id.compare_type_02_02)
    TextView compareType0202;
    @Bind(R.id.compare_type_ll_02)
    LinearLayout compareTypeLl02;
    @Bind(R.id.compare_type_03_01)
    TextView compareType0301;
    @Bind(R.id.compare_type_03_02)
    TextView compareType0302;
    @Bind(R.id.compare_type_ll_03)
    LinearLayout compareTypeLl03;
    @Bind(R.id.compare_type_04_01)
    TextView compareType0401;
    @Bind(R.id.compare_type_04_02)
    TextView compareType0402;
    @Bind(R.id.compare_type_ll_04)
    LinearLayout compareTypeLl04;
    @Bind(R.id.compare_type_05_01)
    TextView compareType0501;
    @Bind(R.id.compare_type_05_02)
    TextView compareType0502;
    @Bind(R.id.compare_type_ll_05)
    LinearLayout compareTypeLl05;
    @Bind(R.id.compare_type_06_01)
    TextView compareType0601;
    @Bind(R.id.compare_type_06_02)
    TextView compareType0602;
    @Bind(R.id.compare_type_ll_06)
    LinearLayout compareTypeLl06;

    ArrayList<CompareBean> compareBeans = new ArrayList<>();
    String previousName,nowName;


    private ICallBack icb;

    Context context;

    public interface ICallBack {
        void callback(Bundle bundle);
    }

    public void setCallBack(ICallBack cb) {
        icb = cb;
    }

    public CompareDialog2(Context context,ArrayList<CompareBean> compareBeans, String previousName, String nowName) {
        super(context, R.style.loadingDialogStyle);
        this.context = context;
        this.compareBeans = compareBeans;
        this.previousName = previousName;
        this.nowName = nowName;
        setContentView(R.layout.dialog_compare);
        ButterKnife.bind(this, this);

        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.gravity = Gravity.CENTER;
        params.width = ScreenUtil.getScreenWidth(context)-ScreenUtil.dp2px(context, 20);
        getWindow().setAttributes(params);

        this.setCanceledOnTouchOutside(true);
        setNum();
    }

    //1-身份确认，2-意识，3-血制品，4-吸氧方式，5-压疮，6-管道
    public void setNum() {
//        this.compareBeans = compareBeans;
        compareNameTv01 .setText(previousName);
        compareNameTv02 .setText(nowName);
        for (int i =0;i<compareBeans.size();i++){
            switch (compareBeans.get(i).getType())
            {
                case 1:
                    compareTypeLl01.setVisibility(View.VISIBLE);
                    compareType0101.setText("身份确认:"+compareBeans.get(i).getPreviou());
                    compareType0102.setText("身份确认:"+compareBeans.get(i).getNow());
                    break;
                case 2:
                    compareTypeLl02.setVisibility(View.VISIBLE);
                    compareType0201.setText("意识:"+compareBeans.get(i).getPreviou());
                    compareType0202.setText("意识:"+compareBeans.get(i).getNow());
                    break;
                case 3:
                    compareTypeLl03.setVisibility(View.VISIBLE);
                    compareType0301.setText("血制品:"+compareBeans.get(i).getPreviou());
                    compareType0302.setText("血制品:"+compareBeans.get(i).getNow());
                    break;
                case 4:
                    compareTypeLl04.setVisibility(View.VISIBLE);
                    compareType0401.setText(compareBeans.get(i).getPreviou());
                    compareType0402.setText(compareBeans.get(i).getNow());
                    break;
                case 5:
                    compareTypeLl05.setVisibility(View.VISIBLE);
                    compareType0501.setText(compareBeans.get(i).getPreviou());
                    compareType0502.setText(compareBeans.get(i).getNow());
                    break;
                case 6:
                    compareTypeLl06.setVisibility(View.VISIBLE);
                    compareType0601.setText(compareBeans.get(i).getPreviou());
                    compareType0602.setText(compareBeans.get(i).getNow());
                    break;
            }
        }
    }


    @OnClick({R.id.sure, R.id.cancel})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sure:
                if (icb != null) {
                    // 这个方法在传入的回调器中实现
                    Bundle bundle = new Bundle();
                    icb.callback(bundle);
                    dismiss();
                }
                break;
            case R.id.cancel:
                dismiss();
                break;
        }
    }

}
